﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;

public partial class Columns : System.Web.UI.Page
{
	public ColumnComponent clsColumnCom;		// 栏目控制类
	public string strColumnIDs;		// 登录用户有权限访问的栏目ID和

	protected void Page_Load(object sender, EventArgs e)
	{
		clsColumnCom = new ColumnComponent();

		strColumnIDs = Session["LoginUserRight"].ToString();

		if (!IsPostBack)
		{
			SetColumnsTree();
		}
	}

	#region 用TreeView显示栏目
	private void SetColumnsTree()
	{
		List<Column> listFirstColumns;		// 一级栏目

		listFirstColumns = clsColumnCom.QueryFirstAdminColumnByColumnIDs(strColumnIDs);		// 根据用户权限查询所有一级栏目

		TreeColumns.Nodes.Clear();		// 清除Tree

		for (int i = 0; i < listFirstColumns.Count; i++)
		{

			TreeNode treeNode;

			treeNode = new TreeNode();

			treeNode.Text = listFirstColumns[i].Name;
			if (listFirstColumns[i].Link != "")
			{
				treeNode.NavigateUrl = listFirstColumns[i].Link + "?id=" + listFirstColumns[i].ID;
			}
			treeNode.SelectAction = TreeNodeSelectAction.Expand;
			treeNode.Target = "content";

			AddTree(listFirstColumns[i].ID, treeNode);

			TreeColumns.Nodes.Add(treeNode);
		}

		//TreeNode tNode;

		//tNode = new TreeNode();
		//tNode.Text = "退出";
		//tNode.NavigateUrl = "Login.aspx";
		//tNode.Target = "_top";
		//TreeColumns.Nodes.Add(tNode);
	}

	private void AddTree(int nFatherID, TreeNode treeNodeFatherNode)
	{
		List<Column> list;
		List<Column> listChildColumns;

		list = clsColumnCom.QueryByFatherIDColumnIDs(nFatherID, strColumnIDs);

		for (int i = 0; i < list.Count; i++)
		{
			TreeNode treeNode;

			treeNode = new TreeNode();

			treeNode.Text = list[i].Name;
			if (list[i].Link != "")
			{
				treeNode.NavigateUrl = list[i].Link + "?id=" + list[i].ID;
			}
			treeNode.SelectAction = TreeNodeSelectAction.Expand;
			treeNode.Target = "content";

			listChildColumns = clsColumnCom.QueryByFatherIDColumnIDs(list[i].ID, strColumnIDs);
			if (listChildColumns.Count > 0)
			{
				AddTree(list[i].ID, treeNode);
			}

			treeNodeFatherNode.ChildNodes.Add(treeNode);
		}
	}
	#endregion
}
